<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改商品</title>
<link rel="stylesheet" href="css/toastr.css">
</head>
<body>
	商品id：<input type="text" name ="goodsId" id ="goods_id" readonly="readonly" value="${good.goodsId }"><br>
	商品名称：<input type="text" name="goodsName" id="goods_name" value="${good.goodsName }"><br/>
	商品类型：<input type="text" name="goodsType" id="goods_type" value="${good.goodsType }"><br/>
	商品价格：<input type="text" name="goodsPrice" id="goods_price" value="${good.goodsPrice }"><br/>
	商品数量：<input type="text" name="goodsCount" id="goods_count" value="${good.goodsCount }"><br/>
	<button type="button" id="btn">修改</button>
</body>
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="js/toastr.js"></script>
<script type="text/javascript">
	$("#btn").click(function () {
		//正则表达式
		reg_goods_name = /^[a-zA-Z0-9\u4E00-\u9FA5]{2,6}$/;
		reg_goods_type = /^[a-zA-Z0-9\u4E00-\u9FA5]{2,6}$/;
		reg_goods_price = /^[a-zA-Z0-9\u4E00-\u9FA5]{2,6}$/;
		reg_goods_count = /^[a-zA-Z0-9\u4E00-\u9FA5]{2,6}$/;
		
		//获取数据
		var goods_id = $("#goods_id").val();
		var goods_name = $("#goods_name").val();
		var goods_type = $("#goods_type").val();
		var goods_price = $("#goods_price").val();
		var goods_count = $("#goods_count").val();
		
		if(!reg_goods_name.test(goods_name)){
			toastr.error("你输入的商品名称不正确");
		}else if(!reg_goods_type.test(goods_type)){
			toastr.error("你输入的商品类型不正确");
		}else if(!reg_goods_price.test(goods_price)){
			toastr.error("你输入的商品价格不正确");
		}else if(!reg_goods_count.test(goods_count)){
			tpastr.error("你输入的商品数量不正确");
		}else{ 
			//调修改方法
			updateGoods(goods_id,goods_name,goods_type,goods_price,goods_count);
		} 
	})

	//修改方法
	function updateGoods(goods_id,goods_name,goods_type,goods_price,goods_count) {
		$.ajax({
			url:"updateGoods.do",
			type:"POST",
			data:{"goodsId":goods_id,"goodsName":goods_name,"goodsType":goods_type,"goodsPrice":goods_price,"goodsCount":goods_count},
			success:function(data){
				/* alert(data) */
				toastr.error(data);
				window.location.href="queryAll.do"
			},
			error:function(){
				toastr.error("请求失败，异常");
			}
		})
	}

</script>
</html>